package org.example.myleet.learn.bank;

import java.math.BigDecimal;
import java.util.StringJoiner;

public class Account {

    private String name;

    private BigDecimal balance;

    public Account(String name, double initializedAmount) {
        this.name = name;
        this.balance = BigDecimal.valueOf(initializedAmount);
    }

    public String getName() {
        return name;
    }

    public BigDecimal getBalance() {
        return balance;
    }

    public void transfer(BigDecimal amount) {
        balance = balance.add(amount);
    }

    public void withdraw(BigDecimal amount) {
        balance = balance.subtract(amount);
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", Account.class.getSimpleName() + "[", "]")
                .add("name='" + name + "'")
                .add("balance=" + balance)
                .toString();
    }
}
